#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int s[N];
int n;
int main()
{
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (int i = 0, j = 0; i < n; i++) {
		s[arr[i]]++;
		while (j <= i && s[arr[i]] > 1) {
			s[arr[j]]--;
			j++;
		}
		ans = max(ans, i - j + 1);
	}
	cout << ans << endl;
	return 0;
}